<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%
	List catalogList = (List)request.getAttribute("catalogList");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>catalog列表</title>
    <%@include file="/comhead.jsp" %>
    <script type="text/javascript">
	function deleteCatalogHandler(dm){
		var cid = dm.catalogid;
		var res = confirm("你确定要删除类别："+cid+" ？");
		if(res){
			$.ajax({
				url: "deleteCatalog.do",
				data: {
					catalog : cid
				},
				success: function(data, textStatus){
					data = $.parseJSON(data);
					if(data.success){
						alert("成功删除！");
						window.location.reload();
					}else{
						var msg = data.messages.join("，");
						alert(msg);
					}
				}
			});
		}
	}
    
	function reloadCacheHandler(){
		$.ajax({
			url: "reloadCatalogCache.do",
			data: {},
			success: function(data, textStatus){
				data = $.parseJSON(data);
				if(data.success){
					alert("成功刷新缓存！");
					window.location.reload();
				}else{
					Tas.showError(data.messages);
				}
			}
		});
	}
    
    $(document).ready(function(){
		$("#reloadCache").click(reloadCacheHandler);
	});
    </script>
  </head>
  <body>
    <a href="addCatalog.do">添加分类</a>&nbsp;
    <a id="reloadCache" href="###">重载缓存</a>
    <table class="table_show1" border="1px" bordercolor="#ccbbaa">
      <thead>
        <tr>
          <td>上级</td>
          <td>名称</td>
          <td>叶子节点</td>
          <td>显示顺序</td>
          <td>操作</td>
        </tr>
      </thead>
      <tbody>
<%
	for(int i=0;i<catalogList.size();i++){
		Map rec = (Map)catalogList.get(i);
%>
        <tr>
          <td><%=rec.get("parent")%></td>
          <td><%=rec.get("name")%></td>
          <td><%=rec.get("leaf")%></td>
          <td><%=rec.get("order")%></td>
          <td>
            <a href="editCatalog.do?catalog=<%=rec.get("id")%>">编辑</a>&nbsp;
            <a href="###" onclick="deleteCatalogHandler(this);" catalogid="<%=rec.get("id")%>">删除</a>
          </td>
        </tr>
<%
	}
%>
      </tbody>
    </table>
  </body>
</html>